﻿using Inovout.Kuajing.Exports.Models;
using Inovout.Organizations.Models;
using Inovout.Services;
using NHibernate.Criterion;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Inovout.Kuajing.Exports.Services
{
    public class ConsigneeService : RepositoryService<Consignee>, IConsigneeService
    {
        public List<Consignee> FindByKeyAndOrganizationUnit(OrganizationUnit organizationUnit)
        {
            if (organizationUnit != null)
            {
                return (List<Consignee>)base.Repository.FindAll(Restrictions.Eq("Organization.Id", (object)organizationUnit.Id));
            }
            else
            {
                IRepositoryService<Consignee> consigneeService = ComponentRegistry.Resolve<IRepositoryService<Consignee>>();
                return consigneeService.Query().ToList<Consignee>();
            }
        }

        public Consignee FindByOrganizationUnit(OrganizationUnit organizationUnit) 
        {
            if (organizationUnit != null)
            {
                return base.Repository.Find(Restrictions.Eq("Organization.Id", (object)organizationUnit.Id));
            }
            else
            {
                IRepositoryService<Consignee> consigneeService = ComponentRegistry.Resolve<IRepositoryService<Consignee>>();
                return consigneeService.Query().ToList<Consignee>().Single();
            }
        }
    }
}
